package jmine.tec.batch.domain;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import jmine.tec.persist.annotation.Alias;
import jmine.tec.persist.annotation.Comment;
import jmine.tec.persist.annotation.Constraint;

import org.hibernate.annotations.Type;
import org.hibernate.validator.NotNull;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;
import bancosys.tec.utils.date.Date;

/**
 * Entidade que armazena o estado de um conjunto de processos.
 * 
 * @author Rafael Volpato
 * @date Jul 6, 2010
 */
@Entity
@Table(name = "PROCESSING_STATE")
@Alias("PROSTT")
@SequenceGenerator(name = "SEQ_PROSTT", sequenceName = "SEQ_PROSTT")
@DiscriminatorValue(value = "0")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Constraint(suffix = "0")
@DiscriminatorColumn(name = "DISCRIMINATOR", discriminatorType = DiscriminatorType.INTEGER)
@Comment(table = "PROCESSING_STATE", column = "DISCRIMINATOR", value = "IDENTIFICADOR DO TIDO DA PROCESSING STATE.")
@Documentation("ARMAZENA O ESTADO D PROCESSAMENTO DE UM ELEMENTO PROCESSADO.")
public abstract class ProcessingState extends PersistableBusinessObject {

    private Long id;

    private Date date;

    /**
     * @return the id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_PROSTT")
    @Column(name = "COD_PROCESSING_STATE")
    @Documentation("CODIGO DO ESTADO DO PROCESSAMENTO")
    public Long getId() {
        return this.id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the date
     */
    @NotNull
    @Column(name = "DT_PROCESS")
    @Documentation("DATA CORRENTE DO PROCESSO")
    @Type(type = "bancosys.tec.persist.hibernate.type.DateType")
    public Date getDate() {
        return this.date;
    }

    /**
     * @param date the date to set
     */
    public void setDate(Date date) {
        this.date = date;
    }

    /**
     * Efetua a transição de estado após a conclusão do processo {@link MProcess}.
     * 
     * @param mprocess {@link MProcess}
     */
    public abstract void onFinishMProcess(MProcess mprocess);
}
